package com.example.administrator.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.myapplication.util.DB;

public class MainActivity extends AppCompatActivity {

    private EditText usernameEd;
    private EditText studentidEd;
    private Button loginBtn;
    private TextView forgerStudentIdTv;
    private TextView signInTv;
    private String usernameStr;
    private String studentStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initEvent();
    }

    private void initView() {
        usernameEd = findViewById(R.id.username_et);
        studentidEd = findViewById(R.id.student_id_et);
        loginBtn = findViewById(R.id.login_btn);
        forgerStudentIdTv = findViewById(R.id.forget_student_id_tv);
        signInTv = findViewById(R.id.sign_in_tv);
    }


    private void initData() {
        usernameStr = usernameEd.getText().toString() + "";
        studentStr = studentidEd.getText().toString() + "";

    }

    private void initEvent() {
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initData();
                DB db = new DB(MainActivity.this);
                db.loginSelect(usernameStr,studentStr);
                Boolean result = db.loginSelect(usernameStr,studentStr);
                if(result){
                    Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
                }

            }
        });
        forgerStudentIdTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        signInTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,SignInActivity.class);
                startActivity(intent);
            }
        });
    }
}

